<?php
	//ini_set("display_errors","2");
	//ERROR_REPORTING(E_ALL);
	
	require_once 'lib/classes/jspeed.class.php';
	
	$len = 10000000;
	$script = "
		var str = 'It\'s Nick\'s World!';
		for (i=0;i<1;i++) {
			j = i + 1;
		}
	
		for (i = 0, j = 0; i < $len; i++, j++) {
			if (i == 4) {
				var tmp = i / 2;
			}
			
			if ((i % 2) == 0) {
				var tmp = i / 2;
				tmp = Math.min(i,tmp);
				i++;
			}
		}
	var arr = new Array(1000000);
	for (var i = 0; i < arr.length; i++) {}
	";
	
	$engine = new JSpeed($script, false);
	$engine->optimize();
	echo $engine->post[0];
	
?>
<html>
	<head>
		<title>JSpeed Test</title>
	</head>
	<script type="text/javascript">
		/*
		function ineffecientMin() {
		  var date1= new Date();
		  startTime = date1.getTime();
		  var minimun;
		  for (var i=0;i<500000;i++) {
		    minimun = Math.min(i,i+1);
		  }
		  var date2= new Date();
		  endTime = date2.getTime();

		  return endTime-startTime;
		}

		function effecientMin() {
		  var date1= new Date();
		  startTime = date1.getTime();
		  var minimun;
		  for (var i=0;i<500000;i++) {
		    minimun = i < (i+1) ? i : (i+1);
		  }
		  var date2 = new Date();
		  endTime = date2.getTime();

		  return endTime-startTime;
		}*/
		/*
		function ineffecient() {
		  var date1= new Date();
		  startTime = date1.getTime();
		  var result = 0;
		  var elts = new Array();
		  for (var data=0;data<50000;data++) {
		    elts.push(data);
		  }
		  var date2= new Date();
		  endTime = date2.getTime();

		  return endTime-startTime;
		}

		function effecient() {
		  var date1= new Date();
		  startTime = date1.getTime();
		  var result = 0;  
		  var elts = new Array();
		  var i = 0;
		  for (var data=0;data<50000;data++) {
		    elts[i++] = data;
		  }
		  var date2 = new Date();
		  endTime = date2.getTime();

		  return endTime-startTime;
		}
		*/
		/*function ineffecientIteration() {
		  var elts1 = [];
		  var elts2 = [];

		  for (var i=0;i<4000;i++) {
		    elts1[i] = i;
		    elts2[i] = i;
		  }

		  var found = false;
		  var date1= new Date();
		  startTime = date1.getTime();

		  for( var i = 0; i < elts1.length; i++ ) {
		    for( var j = 0; j < elts2.length; j++ ) {
		      if (elts1[i] === elts2[j]) {
		        found = true;
		        break;
		      }
		    }
		  }
		  var date2 = new Date();
		  endTime = date2.getTime();

		  return endTime-startTime;
		}

		function effecientIteration() {
		  var elts1 = [];
		  var elts2 = [];

		  for (var i=0;i<4000;i++) {
		    elts1[i] = i;
		    elts2[i] = i;
		  }
		  var found = false;
		  var date1= new Date();
		  startTime = date1.getTime();
		  var tmpelts2 = elts2.join(',');

		  for( var i = 0; i < elts1.length; i++ ) {
		    if (tmpelts2.indexOf(elts1[i])) {
		      found = true;
		    }
		  }
		  var date2 = new Date();
		  endTime = date2.getTime();

		  return endTime-startTime;
		}
		alert(ineffecientIteration());
		alert(effecientIteration());*/
	</script>
	<body>
		<div id="output"></div>
		<?= $engine->benchmark() ?>
	</body>
</html>